package com.jchy.photo;

import java.io.File;
import java.util.GregorianCalendar;
import java.util.Calendar;

public class Date 
{
	public static String MonthDayYear(String inYearMonthDay)
	{
		String result = inYearMonthDay;
		
		if(inYearMonthDay.length() == 8 && Date.isNumeric(inYearMonthDay))
			result = inYearMonthDay.substring(4,6) + "/" +
			         inYearMonthDay.substring(6,8) + "/" +
			         inYearMonthDay.substring(0,4);
		
		return result;
	}
	
	private static boolean isNumeric(String inString)
	{
		boolean result = true;
		char[] charArray =  inString.toCharArray();
		
		for(int i=0; i< inString.length(); i++)
			if(charArray[i] < '0' || charArray[i] > '9')
				result = false;
		
		return result;
	}
	
	public static String GetModifiedDateYearMonthDay(File inFile)
	{
		String result = "";
		
		long modifiedLong = inFile.lastModified();
		
		GregorianCalendar modifiedGC = new GregorianCalendar();
		
		modifiedGC.setTimeInMillis(modifiedLong);
		
		if(modifiedGC != null)
		{
			int iYear = modifiedGC.get(Calendar.YEAR);
			int iMonth = modifiedGC.get(Calendar.MONTH);
			int iDay = modifiedGC.get(Calendar.DAY_OF_MONTH);
			String sYear = "";
			String sMonth = "";
			String sDay = "";
			if(iYear == 0)
				sYear = "0000";
			else if(iYear < 10)
				sYear = "000" + String.valueOf(iYear);
			else if(iYear < 100)
				sYear = "00" + String.valueOf(iYear);
			else if(iYear < 1000)
				sYear = "0" + String.valueOf(iYear);
			else sYear = String.valueOf(iYear);
			
			if(iMonth+1 == 0)
				sMonth = "00";
			else if(iMonth+1 < 10)
				sMonth = "0" + String.valueOf(iMonth+1);
			else sMonth = String.valueOf(iMonth+1);

			if(iDay == 0)
				sDay = "00";
			else if(iDay < 10)
				sDay = "0" + String.valueOf(iDay);
			else sDay = String.valueOf(iDay);

			result = sYear + sMonth + sDay;
		}
		return result;
		
	}

}
